<script>
	import {
		Login,
		getProducts,
		getAllcomment,
		getHistoryOrders
	} from '~/api/index'
	import useProductStore from '@/store/modules/product'
	import useSystemStore from '@/store/modules/system'
	export default {
		data() {
			return {
				systemInfo: {}
			}
		},
		onLaunch: function() {
			this.systemInfo = uni.getSystemInfoSync()
			//this.Login()
			console.log('App Launch')

			// #ifdef APP-PLUS
			// 判断是否是 iOS 平台
			if (this.systemInfo.platform === 'android') {
				let Color = plus.android.importClass("android.graphics.Color");
				plus.android.importClass("android.view.Window");
				let mainActivity = plus.android.runtimeMainActivity();
				let window_android = mainActivity.getWindow();
				let WindowManager = plus.android.importClass("android.view.WindowManager");
				let View = plus.android.importClass("android.view.View");
				//设置为全透明
				window_android.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager
					.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
				window_android.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View
					.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
				window_android.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
				window_android.setNavigationBarColor(Color.TRANSPARENT);
			}
			//#endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			//登录获取token
			Login() {
				let _userInfo = uni.getStorageSync("userInfo");
				console.log(2342342342,_userInfo);
				if (!_userInfo) {
					uni.reLaunch({
						url: '/pages/login/index'
					})
					return
				}


				let _useSystemStore = useSystemStore()
				_useSystemStore.userInfo = _userInfo
				if (_useSystemStore.userInfo.phone)
					_useSystemStore.login(_useSystemStore.userInfo.phone).then(data => {
						this.initData()
					})
				else
					uni.reLaunch({
						url: '/pages/login/index'
					})
			},
			//初始化获取所有产品、评论
			initData() {
				getProducts({}).then(data => {
					useProductStore().products = data.data.map(row => ({
						...row,
						sellOut: row.sellOut === 'true'
					}))
				})
				getAllcomment({}).then(data => {
					useProductStore().comments = data.data
				})
				getHistoryOrders({
					phone: useSystemStore().userInfo.phone
				}).then(data => {
					useSystemStore().myOrders = data.data
				})
			}
		}
	}
</script>

<style lang="scss">
	page,
	.page {
		height: 100vh;
		overflow: hidden;
		font-family: Arial, sans-serif !important;
		box-sizing: border-box;
		padding-bottom: constant(safe-area-inset-bottom);
		/* iOS */
		padding-bottom: env(safe-area-inset-bottom,0px) !important;
		/* Android */
		--status-bar-height:0 !important;
	}


	// padding-bottom: env(safe-area-inset-bottom, 0px) !important; /* 将其设为0来忽略底部安全区 */	
</style>